﻿using System;

namespace RG.Common
{
    public static class TimeStampUtils
    {
        public static int DateDifferenceInMonts(DateTime d1, DateTime d2)
        {
            DateTime fromDate;
            DateTime toDate;
            int month;

            #region проверяем правильно ли нам подсунули даты

            if (d1 > d2)
            {
                fromDate = d2;
                toDate = d1;
            }
            else
            {
                fromDate = d1;
                toDate = d2;
            }

            #endregion

            var inc = 0;

            if ((fromDate.Month + inc) > toDate.Month)
            {
                month = (toDate.Month + 12) - (fromDate.Month + inc);
                inc = 1;
            }
            else
            {
                month = (toDate.Month) - (fromDate.Month + inc);
                inc = 0;
            }

            var year = toDate.Year - (fromDate.Year + inc);

            return month + (year*12);
        }

    }
}
